package com.seesman.application.maintenance.gui.vessel;

import static com.seesman.application.maintenance.common.constants.VesselConstant.BREADTH;
import static com.seesman.application.maintenance.common.constants.VesselConstant.BUILDER;
import static com.seesman.application.maintenance.common.constants.VesselConstant.BUILT_YEAR;
import static com.seesman.application.maintenance.common.constants.VesselConstant.CALL_SIGN;
import static com.seesman.application.maintenance.common.constants.VesselConstant.CLASSIFICATION;
import static com.seesman.application.maintenance.common.constants.VesselConstant.CLASS_NO;
import static com.seesman.application.maintenance.common.constants.VesselConstant.CONSTANT_WEIGHT;
import static com.seesman.application.maintenance.common.constants.VesselConstant.DEAD_WEIGHT;
import static com.seesman.application.maintenance.common.constants.VesselConstant.DEPTH;
import static com.seesman.application.maintenance.common.constants.VesselConstant.DISPLACEMENT;
import static com.seesman.application.maintenance.common.constants.VesselConstant.DRAFT_SUMMER;
import static com.seesman.application.maintenance.common.constants.VesselConstant.GROSS_TONNAGE;
import static com.seesman.application.maintenance.common.constants.VesselConstant.IMO_NO;
import static com.seesman.application.maintenance.common.constants.VesselConstant.LBP;
import static com.seesman.application.maintenance.common.constants.VesselConstant.LIGHT_WEIGHT;
import static com.seesman.application.maintenance.common.constants.VesselConstant.LOA;
import static com.seesman.application.maintenance.common.constants.VesselConstant.NET_TONNAGE;
import static com.seesman.application.maintenance.common.constants.VesselConstant.OFFICIAL_NO;
import static com.seesman.application.maintenance.common.constants.VesselConstant.OWNER;
import static com.seesman.application.maintenance.common.constants.VesselConstant.REGISTRY;
import static com.seesman.application.maintenance.common.constants.VesselConstant.VESSEL_ID;
import static com.seesman.application.maintenance.common.constants.VesselConstant.VESSEL_NAME;
import static com.seesman.application.maintenance.common.constants.VesselConstant.VESSEL_TYPE;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;


/**
 * This class is the Vessel Form, where all the detail information
 * and description of the vessel is manipulated.
 * 
 * 
 * @author jhayne_mjvb
 *
 */
@SuppressWarnings("serial")
public class VesselFrame extends JFrame implements ActionListener {

	private static VesselFrame window;
	
	private String vesselName;
	
	// [START] - Variable Declaration
	private JLabel lblVesselId;
	private JLabel lblVesselName;
	private JLabel lblVesselType;
	private JLabel lblRegistry;
	private JLabel lblOfficialNo;
	private JLabel lblImoNo;
	private JLabel lblCallSign;
	private JLabel lblOwner;
	private JLabel lblBuilder;
	private JLabel lblBuiltYear;
	private JLabel lblClassification;
	private JLabel lblClassNo;
	private JLabel lblGrossTonnage;
	private JLabel lblNetTonnage;
	private JLabel lblLoa;
	private JLabel lblLbp;
	private JLabel lblBreadth;
	private JLabel lblDepth;
	private JLabel lblDeadWeight;
	private JLabel lblLightWeight;
	private JLabel lblConstantWeight;
	private JLabel lblDraftSummer;
	private JLabel lblDisplacement;
	
	private JTextField txtVesselId;
	private JTextField txtVesselName;
	private JTextField txtVesselType;
	private JTextField txtRegistry;
	private JTextField txtOfficialNo;
	private JTextField txtImoNo;
	private JTextField txtCallSign;
	private JTextField txtOwner;
	private JTextField txtBuilder;
	private JTextField txtBuiltYear;
	private JTextField txtClassification;
	private JTextField txtClassNo;
	private JTextField txtGrossTonnage;
	private JTextField txtNetTonnage;
	private JTextField txtLoa;
	private JTextField txtLbp;
	private JTextField txtBreadth;
	private JTextField txtDepth;
	private JTextField txtDeadWeight;
	private JTextField txtLightWeight;
	private JTextField txtConstantWeight;
	private JTextField txtDraftSummer;
	private JTextField txtDisplacement;
	
	private JPanel panelInfo;
	private JPanel panelDesc;	
	// [END] - Variable Declaration
		
	public VesselFrame(String vesselName) {        
        this.vesselName = vesselName;		        
    }
	
	/**
	 * This method make sure that there is only one instance of this class.
	 * 
	 * @param name - String. The vesselName of this frame.
     * @return window - VesselFrame.
	 */
	public static VesselFrame getInstance(String vesselName) {
		
		if(window == null){
            window = new VesselFrame(vesselName);   
            
            try {
    			window.open();
    		} catch (RemoteException e) {
    			e.printStackTrace();
    		} catch (MalformedURLException e) {
    			e.printStackTrace();
    		} catch (NotBoundException e) {
    			e.printStackTrace();
    		}
    		
        }
		
		return window; 
		
	}
	
	/**
	 * This method is use to initialize the form
	 * 
	 * 1 - this was called from the constructor
	 * 2 - this was called from getInstance
	 * 
	 */
	private void open() throws RemoteException, MalformedURLException, NotBoundException { 
		try {
			lblVesselId = new JLabel(VESSEL_ID);
			lblVesselName = new JLabel(VESSEL_NAME);
			lblVesselType = new JLabel(VESSEL_TYPE);
			lblRegistry = new JLabel(REGISTRY);
			lblOfficialNo = new JLabel(OFFICIAL_NO);
			lblImoNo = new JLabel(IMO_NO);
			lblCallSign = new JLabel(CALL_SIGN);
			lblOwner = new JLabel(OWNER);
			lblBuilder = new JLabel(BUILDER);
			lblBuiltYear = new JLabel(BUILT_YEAR);
			lblClassification = new JLabel(CLASSIFICATION);
			lblClassNo = new JLabel(CLASS_NO);
			lblGrossTonnage = new JLabel(GROSS_TONNAGE);
			lblNetTonnage = new JLabel(NET_TONNAGE);
			lblLoa = new JLabel(LOA);
			lblLbp = new JLabel(LBP);
			lblBreadth = new JLabel(BREADTH);
			lblDepth = new JLabel(DEPTH);
			lblDeadWeight = new JLabel(DEAD_WEIGHT);
			lblLightWeight = new JLabel(LIGHT_WEIGHT);
			lblConstantWeight = new JLabel(CONSTANT_WEIGHT);
			lblDraftSummer = new JLabel(DRAFT_SUMMER);
			lblDisplacement = new JLabel(DISPLACEMENT);
			
			txtVesselId = new JTextField();
			txtVesselName = new JTextField();
			txtVesselType = new JTextField();
			txtRegistry = new JTextField();
			txtOfficialNo = new JTextField();
			txtImoNo = new JTextField();
			txtCallSign = new JTextField();
			txtOwner = new JTextField();
			txtBuilder = new JTextField();
			txtBuiltYear = new JTextField();
			txtClassification = new JTextField();
			txtClassNo = new JTextField();
			txtGrossTonnage = new JTextField();
			txtNetTonnage = new JTextField();
			txtLoa = new JTextField();
			txtLbp = new JTextField();
			txtBreadth = new JTextField();
			txtDepth = new JTextField();
			txtDeadWeight = new JTextField();
			txtLightWeight = new JTextField();
			txtConstantWeight = new JTextField();
			txtDraftSummer = new JTextField();
			txtDisplacement = new JTextField();
			
			panelInfo = new JPanel();
			panelDesc = new JPanel();
			
			window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
			window.setTitle("Vessel - SAMPLE");
			window.setSize(1400, 1270);
			window.setResizable(Boolean.FALSE);	  
			
			window.setIconImage(new ImageIcon("icon-image/fix.gif").getImage());
			
			panelInfo.setBorder(BorderFactory.createTitledBorder("Vessel Information"));
			panelDesc.setBorder(BorderFactory.createTitledBorder("Vessel Description"));
			
			GroupLayout panelInfoLayout = new GroupLayout(panelInfo);	
			panelInfo.setLayout(panelInfoLayout);
			panelInfoLayout.setHorizontalGroup(
					panelInfoLayout.createParallelGroup(GroupLayout.LEADING)
					.add(0, 510, Short.MAX_VALUE)
			);
			panelInfoLayout.setVerticalGroup(
					panelInfoLayout.createParallelGroup(GroupLayout.LEADING)
					.add(0, 218, Short.MAX_VALUE)
			);
			
			/*GroupLayout panelDescLayout = new GroupLayout(panelDesc);
			panelDesc.setLayout(panelDescLayout);
			panelDescLayout.setHorizontalGroup(arg0);
			panelDescLayout.setVerticalGroup(arg0);*/
			
			
			GroupLayout layout = new GroupLayout(getContentPane());			
	        getContentPane().setLayout(layout);
			layout.setHorizontalGroup(
					layout.createParallelGroup(GroupLayout.LEADING)
		        );
		        
		        layout.setVerticalGroup(
		            layout.createParallelGroup(GroupLayout.LEADING)
		            .add(layout.createSequentialGroup()
		                .add(txtDisplacement, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
		                .addPreferredGap(LayoutStyle.RELATED)
		                .add(layout.createParallelGroup(GroupLayout.BASELINE)
		                    .add(lblVesselName)
		                    .add(lblVesselName)
		                    .add(lblVesselName))
		                .addPreferredGap(LayoutStyle.RELATED)
		                .add(layout.createParallelGroup(GroupLayout.LEADING)
		                    .add(GroupLayout.TRAILING, layout.createSequentialGroup()
		                        .add(txtDisplacement, GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
		                        .addPreferredGap(LayoutStyle.RELATED)
		                        .add(txtDisplacement, GroupLayout.PREFERRED_SIZE, 92, GroupLayout.PREFERRED_SIZE)
		                        .addPreferredGap(LayoutStyle.RELATED)
		                        .add(lblVesselName))
		                    .add(lblVesselName, GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
		                .addContainerGap())
		        );
			
			pack();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		try {
            window = getInstance("SAMPLE");         
            window.open();
            window.setVisible(true);
        } catch(Exception e){
            e.printStackTrace();
        }
	}
	
	
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}	

}
